import axios from "axios"

let integral = {
    // 发布交流
    release:100,
    // 回复消息
    reply:20
}


// 增加访问量
let VisitsInc = function(baseUrl){
    return axios.get(`${baseUrl}/analysis/visits`);
}
// 增加申请量
let SignedRequestInc = function(baseUrl){
    return axios.get(`${baseUrl}/analysis/signedRequest`);
}
// 增加领养量
let SignedSuccessfullyInc = function(baseUrl){
    return axios.get(`${baseUrl}/analysis/signedSuccessfully`);
}
// 增加发布量
let PublicationInc = function(baseUrl){
    return axios.get(`${baseUrl}/analysis/publication`);
}

/**
 * 增加积分
 * @param {*} baseUrl 
 * @param {*} uid 用户id
 * @param {*} num 数量
 * @returns 
 */
let addIntegral = function(baseUrl,uid,num){
    return axios.get(`${baseUrl}/user/addIntegral?uid=${uid}&num=${num}`);
}

/**
 *  减少积分
 * @param {*} baseUrl 
 * @param {*} uid 用户id
 * @param {*} num 数量
 * @returns 
 */
let subIntegral = function(baseUrl,uid,num){
    return axios.get(`${baseUrl}/user/subIntegral?uid=${uid}&num=${num}`);
}

/**
 * 以2000为上限，当积分大于2千时，按2千算，当不足两千时按照当前积分算
 * 1000积分为一块钱
 * @param {*} param 积分总数
 * @returns 
 *  integral 用掉的积分
 *  discount 折扣的钱数
 */
let useIntegral = function(param){
    let integral = param;
    if(integral>2000){
        integral = 2000;
    }
    return {
        integral,
        discount:integral / 1000
    }
}

export default {
    integral,VisitsInc,SignedRequestInc,SignedSuccessfullyInc,PublicationInc,addIntegral,subIntegral,useIntegral
}